package com.ruoyi.cms.controller.website;

import com.ruoyi.cms.domain.CmsGoods;
import com.ruoyi.cms.service.ICmsGoodsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 商品管理Controller
 *
 * @author houyong
 * @date 2025-11-20
 */
@Tag(name = "CmsSiteGoodsController", description = "CMS商品管理接口 for web前端")
@RestController
@RequestMapping("cms/website/goods")
public class CmsSiteGoodsController extends BaseController {
    @Autowired
    private ICmsGoodsService cmsGoodsService;

    /**
     * 查询商品管理列表
     */
//    @RequiresPermissions("cms:goods:list")
    @Operation(summary = "查询商品管理列表", description = "分页查询商品管理信息列表")
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "操作成功",
                    content = @Content(mediaType = "application/json",
                            schema = @Schema(implementation = TableDataInfo.class)))
    })
    @GetMapping("/list")
    public TableDataInfo list(@Parameter(description = "商品管理查询参数") CmsGoods cmsGoods) {
        startPage();
        List<CmsGoods> list = cmsGoodsService.selectCmsGoodsList(cmsGoods);
        return getDataTable(list);
    }

    /**
     * 获取商品管理详细信息
     */
//    @RequiresPermissions("cms:goods:query")
    @Operation(summary = "获取商品管理详情", description = "根据商品ID获取商品管理详细信息")
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "操作成功",
                    content = @Content(mediaType = "application/json",
                            schema = @Schema(implementation = AjaxResult.class)))
    })
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@Parameter(description = "商品ID", required = true) @PathVariable("id") Long id) {
        return success(cmsGoodsService.selectCmsGoodsById(id));
    }

}